package com.caszx.chargingpile.user;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.mapapi.map.Marker;
import com.baidu.navisdk.adapter.BNRoutePlanNode;
import com.baidu.navisdk.adapter.BaiduNaviManager;
import com.caszx.chargingpile.activity.BNGuideActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by think on 2016/2/18.
 */
public class LocationManager {

   // private static  BDLocation location;
    private  double mLongitude ;
    private  double mLatitude ;
    private  String mCityName ;

    private  double mUserLongitude ;
    private  double mUserLatitude ;
    private  String mUserCityName ;
    private static LocationManager install;
    public static final String ROUTE_PLAN_NODE = "routePlanNode";
    public static LocationManager getInstance(){
        if(install == null){
            install = new LocationManager();
//            location = new BDLocation();
//            location.setLongitude(117.1424540000);
//            location.setLatitude(31.8370050000);
        }
        return install;
    }


    public void clear(){
        //location =null;
        install =null;
        mCityName = null;
    }

//    public BDLocation getBDLocation(){
//        return  location;
//    }


    public double getUserLongitude() {
        return mUserLongitude;
    }

    public void setUserLongitude(double userlongitude) {
        this.mUserLongitude = userlongitude;
    }

    public double getUserLatitude() {
        return mUserLatitude;
    }

    public void setUserLatitude(double userlatitude) {
        this.mUserLatitude = userlatitude;
    }

    public double getLongitude() {
        return mLongitude;
    }

    public void setLongitude(double longitude) {
        this.mLongitude = longitude;
    }

    public double getLatitude() {
        return mLatitude;
    }

    public void setLatitude(double latitude) {
        this.mLatitude = latitude;
    }

    public String getCityName() {
        return mCityName;
    }

    public void setCityName(String cityName) {
        this.mCityName = cityName;
    }

    public String getUserCityName() {
        return mUserCityName;
    }

    public void setUserCityName(String usercityName) {
        this.mUserCityName = usercityName;
    }

//    public void setBDLocation(BDLocation location){
//        if(location == null)return;
//        mLongitude = location.getLongitude()+"";
//        mLatitude = location.getLatitude()+"";
//        mCityName = location.getCity();
//    }



    public void routeplanToNavi(Activity context, double start_longitude, double start_latitude,String start_title,
                                 double end_longitude, double end_latitude,String end_title
    ) {
        BNRoutePlanNode sNode = null;
        BNRoutePlanNode eNode = null;
        sNode = new BNRoutePlanNode(start_longitude, start_latitude, start_title, null, BNRoutePlanNode.CoordinateType.BD09LL);
        eNode = new BNRoutePlanNode(end_longitude, end_latitude, end_title, null, BNRoutePlanNode.CoordinateType.BD09LL);
        if (sNode != null && eNode != null) {
            List<BNRoutePlanNode> list = new ArrayList<>();
            list.add(sNode);
            list.add(eNode);
            BaiduNaviManager.getInstance().launchNavigator(context, list, 1, true, new StationRoutePlanListener(sNode,context));
        }
    }

    private class StationRoutePlanListener implements BaiduNaviManager.RoutePlanListener {
        private BNRoutePlanNode mBNRoutePlanNode = null;
        private Context context;

        public StationRoutePlanListener(BNRoutePlanNode node,Context context) {
            mBNRoutePlanNode = node;
            this.context = context;
        }

        @Override
        public void onJumpToNavigator() {
			/*
			 * 设置途径点以及resetEndNode会回调该接口
			 */
            Intent intent = new Intent(context, BNGuideActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode);
            intent.putExtras(bundle);
            context.startActivity(intent);

        }

        @Override
        public void onRoutePlanFailed() {
            Toast.makeText(context, "算路失败", Toast.LENGTH_SHORT).show();
        }
    }
}
